<?php 
include_once("../includes/page_utf_class.php");
include("../lang/cn/company_type_config.php");
include_once("../module/product/includes/plugin_tarento_class.php");
$sales_channel_cfg=array(
    'sales_channel_buyer'=>'代购',
    'sales_channel_netshop'=>'网店',
    'sales_channel_wxshop'=>'微商',
    'sales_channel_offline'=>'实体店',
    
);

$sales_type_cfg=array(
                        '母婴产品',
                    	'美妆护肤产品',
                    	'保健用品',
                    	'日化产品',
                    	'厨房用具',
                    	'进口零食',

);

if ($_GET['act'] == 'detail' && $_GET['id']) {//详情
    
    $sql = "select a.*,b.name,b.qq,b.weixin,b.sex,b.mobile,b.birthday,c.invite_code from " . TARENTOAPPLY . " AS a left join " . MEMBER . " AS b ON a.member_id=b.userid left join ".TARENTO." as c on a.member_id=c.member_id where a.id={$_GET['id']}";
    $db->query($sql);
    $de = $db->fetchRow();
    if($de['birthday']=='0000-00-00'){
    	$de['birthday'] = '';
    	$de['age'] = 0;
    }else{
	    $de['age'] = floor((time() - strtotime($de['birthday'])) / 365 / 86400);
    }
    
    $smarty_tpl = "tarento_apply_detail.htm";
} else {//列表
    
    $str = "";
    if ($_GET['member_id'] > 0) {
        $str .= " and a.member_id={$_GET['member_id']}";
    }
    foreach ($sales_channel_cfg as $key => $item) {
        if ($_GET['sales_channel'] == $key) {
            $str .= " and a.{$key}!=''";
        }
    }
    if ($_GET['sales_type']) {
        $str .= " and a.sales_type like '%{$_GET['sales_type']}%'";
    }
    if($_GET['status']=='1'){
        $str .= " and (c.invite_code='' or c.invite_code is null) ";
    }
    if($_GET['status']=='2'){
        $str .= " and c.invite_code!='' and c.invite_code is not null ";
    }
    
    $sql = "select a.*,b.name,b.qq,b.weixin,b.sex,b.birthday,c.invite_code from " . TARENTOAPPLY . " AS a left join " . MEMBER . " AS b ON a.member_id=b.userid left join ".TARENTO." as c on a.member_id=c.member_id where 1  {$str}";
    // =============================
    $page = new Page();
    $page->listRows = 20;
    if (! $page->__get('totalRows')) {
        $db->query($sql);
        $de['count'] = $page->totalRows = $db->num_rows();
    }
    $de['count'] = $de['count'] ? $de['count'] : $_GET['totalRows'];
    $sql .= "  limit " . $page->firstRow . "," . $page->listRows;
    $de['page'] = $page->prompt();
    // =============================
    $db->query($sql);
    $ss = $db->getRows();
    foreach ($ss as $k) {
    	if($k['birthday']=='0000-00-00'){
    		$k['birthday'] = '';
    		$k['age'] = 0;
    	}else{
	        $k['age'] = floor((time() - strtotime($k['birthday'])) / 365 / 86400);
    	}
        $k['sales_channel'] = '';
        
        foreach ($sales_channel_cfg as $key => $item) {
            if ($k[$key]) {
                $k['sales_channel'] .= $item . ",";
            }
        }
        $k['sales_channel'] = rtrim($k['sales_channel'], ',');
        $list[] = $k;
    }
    $de['list'] = $list;
    $smarty_tpl = "tarento_apply_list.htm";
}
$tpl->assign("de",$de);
$tpl->assign("config",$config);
$tpl->assign("sales_channel_cfg",$sales_channel_cfg);
$tpl->assign("sales_type_cfg",$sales_type_cfg);
$tpl->display($smarty_tpl);
?>